<template>
  <div class="list-content">
    <div v-show="!dialogFalg">
      <el-form :inline="true" :model="formInline" class="demo-form-inline" @submit.native.prevent>
        <el-form-item v-if="isMuilUnitUser">
          <el-select filterable @change="getData(1)" v-model="formInline.orgIds" placeholder="请选择业主单位">
            <el-option
              v-for="item in orgOptions"
              :key="item.organizationId"
              :label="item.shortName"
              :value="item.organizationId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button class="form-search-btn" type="primary" @click="getList(1)">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading"
        :data="tableData"
        ref="mainTable"
        style="width: 100%">
        <el-table-column
        label="序号"
        type="index"
        width="50">
        </el-table-column>
        <el-table-column
        prop="orgName"
        label="业主单位">
        </el-table-column>
        <el-table-column
        prop="areaCount"
        label="分区数量">
        </el-table-column>
        <el-table-column 
        label="操作"
        width="140">
          <template slot-scope="scope">
            <el-button  @click="showDetail(scope.$index, scope.row)" type="text" size="small">清单</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="sizeChange"
        @current-change="pageChange"
        :current-page="formInline.currentPageIndex"
        :page-sizes="[10, 50, 100]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="formInline.currentPageTotal">
      </el-pagination>
    </div>
    <transition name="el-zoom-in-top">
        <!-- 单个单位预案列表 -->
        <safe-list v-if="dialogFalg" :organizationId="transPageOrgId" :organizationName="transPageOrgName" :hasFather="hasFather" :returnFun="returnFather"></safe-list>
    </transition>
  </div>
</template>

<script>
import {getTeamPointAreaList } from '@/api/inspect'
import util from '@/utils/util'
import { getOrgList} from '@/api/org'
import safeList from './InspectAreaList'

export default {
  name: 'InspectAreaUnitList',
  props:['param'],
  components: { 
    safeList
  },
  data () {
    return {
      util:util,
      isMuilUnitUser:this.$store.state.userinfo.isMuilUnitUser,
      formInline: {
        orgIds:this.$store.state.userinfo.isMuilUnitUser ? this.$store.state.userinfo.organizationIds : this.$store.state.userinfo.org.id,
        currentPageSize: 10,
        currentPageIndex: 1,
        currentPageTotal: 0,
      },
      accountName:this.$store.state.userinfo.accountName,
      defaultImg: this.GLOBAL.defaultImg,
      tableData: [],//表格数据
      staticObj:{},//头部各状态个数统计
      orgOptions: [{organizationId: this.$store.state.userinfo.organizationIds,shortName: "全部业主单位"}],
      loading: false,
      dialogFalg: false,
      hasFather: true,
      transPageOrgId: '',
      transPageOrgName: ''
    }
  },
  created:function() {
    this.getList()    
    if(this.isMuilUnitUser)
       getOrgList({queryType: 0}).then((data)=>{
          this.orgOptions.push.apply(this.orgOptions,data.data);
       }) 
  },
  methods: {
    sizeChange(_pageSize) {//页码切换
      this.getList(1,_pageSize) 
    },
    pageChange(_pageIndex) {//翻页
      this.getList(_pageIndex) 
    },
    getData(_pageIndex){
      this.getList(_pageIndex) 
    },
    getList(_pageIndex, _pageSize) {//获取列表
      if(_pageIndex){
        this.formInline.currentPageIndex = _pageIndex
      }
      if(_pageSize){
          this.formInline.currentPageSize = _pageSize
      }
      this.loading =true;
      getTeamPointAreaList({
        queryType:1,
        orgIds :this.formInline.orgIds,
        pageIndex: this.formInline.currentPageIndex -1,
        pageSize: this.formInline.currentPageSize,
      }).then((result) => {
        this.formInline.currentPageTotal = result.total;
        this.tableData = result.data;
        this.loading =false;
      }) 
    },
    showDetail(index, row) {//展开详情
      if(row) {
        this.transPageOrgId = row.orgId
        this.transPageOrgName = row.orgName
        this.dialogFalg = true
      }
    },
    // 返回父页面（供子组件调用）
    returnFather() {
        this.dialogFalg = false
        this.getData(1)
    }
  },
}
</script>